home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 4 code / A⁄ROSE / OSmainƒ / osmain.c < prev    next >
Encoding:
Text File  |  1990-08-28  |  4.5 KB  |  185 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    osmain.c
  4. #
  5. #    Example of a rather minimal A/ROSE download file
  6. #
  7. #    The "ClientAppli" application will find "myTask" on a MCP card, 
  8. #   and have the messages sent to it echoed.
  9. #
  10. #    Components:
  11. #                osmain.c
  12. #                myTask.c
  13. #
  14. ------------------------------------------------------------------------------*/
  15.  
  16.  
  17. /* -------------- MPW: select the following lines + <ENTER> ------
  18.  
  19. C osmain.c  -r
  20. C myTask.c  -r
  21. Link -t 'DMRP' -c 'RWM ' ∂
  22.     osmain.c.o ∂
  23.     myTask.c.o ∂
  24.     ::OS.o ∂
  25.     ::osglue.o ∂
  26.     -o start
  27.     
  28. ::Download  start
  29. ---------------------------------------------------------------- */
  30.  
  31.  
  32. // the following definitions come from the A/ROSE include file "os.h"
  33.  
  34. typedef long tid_type;
  35.  
  36. struct ST_Registers
  37. {
  38.     long    D_Registers [8];        // D0 - D7 
  39.     long    A_Registers [8];        // A0 - A7  Note: A7 not used
  40.     long    PC;                        // Program Counter
  41. };
  42.  
  43. struct ST_PB
  44. {
  45.     char    *CodeSegment;            // memory region on card for code
  46.     char    *DataSegment;            // memory region on card for global data
  47.     char    *StartParmSegment;        // memory region on card for start parameters
  48.     struct    ST_Registers InitRegs;    // initial register set for starting task
  49.     long    stack;                    // initial stack size (in bytes)
  50.     long    heap;                    // initial heap size (in bytes)
  51.     short    return_code;            // error code if task not started (Tid = 0)
  52.     unsigned char priority;            // priority of task (in bytes)
  53.     tid_type    ParentTID;            // TID of Parent on Network/Host
  54. };
  55.  
  56. typedef struct ST_PB ST_PB;
  57.  
  58.  
  59.  
  60. // the following declarations come from arose.h
  61.  
  62. typedef unsigned long     OSlong;
  63. typedef unsigned short     OSshort;
  64. typedef unsigned char     OSchar;
  65.  
  66. //    gCommon - A/ROSE common data area
  67.  
  68. struct    gCommon        //    Located at 0x400 on the MCP card
  69. {
  70.     OSshort    gRelease;            //    release and version number
  71.     OSchar    gProcessor;            //    Type of processor        
  72.     OSchar    gCardRun;            //    Set zero by download, non-zero by O/S
  73.     OSshort    gBoardID;            //    Board id of card        
  74.     OSlong    gTID;                //    Current Task ID            
  75.     OSchar    gDebugOn;            //    non-zero if debugger running        
  76.     OSchar    gMajorFlag;            //    major processing flag    
  77.     OSlong    gInitA5;            //    Initial A5                
  78.     // ................
  79.     // many, many other fields contained in this structure: look up in arose.h !
  80.     // ................
  81. };
  82.  
  83. typedef struct gCommon gCommon;
  84.  
  85. #define        cMaxMsg        500            //    Maximum number of messages
  86. #define        cOSStack    4096        //    size of OS Stack
  87.  
  88. // the following two lines come from siop.h
  89.  
  90. #define    TICKS_PS    19                //    19 ticks per second    
  91. #define    TICK_MIN_MAJ 8                //   8 minor ticks per major tick
  92.  
  93. // prototypes
  94.  
  95. void osinit ();
  96. void osstart ();
  97. void name_server ();
  98. void ICCM ();
  99. void myTask ();
  100. extern    tid_type        GetTID();
  101. extern    struct gCommon    *GetgCommon();
  102. extern    tid_type        StartTask(struct ST_PB *);
  103.  
  104. void StartNameServer(ST_PB *pb);    // the Name Manager
  105. void StartICCManager(ST_PB *pb);    // you guess it!
  106. void StartmyTask(ST_PB *pb);        // and our sample task
  107.  
  108.  
  109. pascal void illegal ()
  110.         extern    0x4afc;
  111.  
  112. main ()
  113. {
  114.     struct ST_PB stpb;    // Start parameter block
  115.  
  116.     // Init OS with cMaxMsg messages and cStackOS stack
  117.  
  118.     osinit (cMaxMsg, cOSStack);
  119.     
  120.     StartNameServer(&stpb);    // the Name Manager
  121.     StartICCManager(&stpb);    // you guess it!
  122.     StartmyTask(&stpb);        // and our sample task
  123.  
  124.     // start all other required managers and tasks
  125.  
  126.     
  127.     osstart (TICK_MIN_MAJ, TICKS_PS);    // Start operating system
  128.  
  129.     illegal ();      // should never get here!
  130.     
  131. } // main()
  132.  
  133.  
  134. void StartNameServer(ST_PB *pb)
  135. // priority 31, 4k stack, 0 heap
  136. {
  137.     pb -> CodeSegment = 0;
  138.     pb -> DataSegment = 0;
  139.     pb -> StartParmSegment = 0;
  140.     pb -> stack = 4096;
  141.     pb -> heap = 0;
  142.     pb -> priority = 31;
  143.     pb -> InitRegs.PC = name_server;
  144.     pb -> InitRegs.A_Registers [5] = GetgCommon() -> gInitA5;
  145.     pb -> ParentTID = GetTID();
  146.     
  147.     if (StartTask (pb) == 0)
  148.         illegal ();
  149. }
  150.  
  151. void StartICCManager(ST_PB *pb)
  152. // priority 31, 128-byte stack, 0 heap
  153. {
  154.     pb -> CodeSegment = 0;
  155.     pb -> DataSegment = 0;
  156.     pb -> StartParmSegment = 0;
  157.     pb -> stack = 128;
  158.     pb -> heap = 0;
  159.     pb -> priority = 31;
  160.     pb -> InitRegs.PC = ICCM;
  161.     pb -> InitRegs.A_Registers [5] = GetgCommon() -> gInitA5;
  162.     pb -> ParentTID = GetTID();
  163.     
  164.     if (StartTask (pb) == 0)
  165.         illegal ();
  166. }
  167.  
  168.  
  169. void StartmyTask(ST_PB *pb)
  170. // priority 10, 4k stack, 0 heap
  171. {
  172.     pb -> CodeSegment = 0;
  173.     pb -> DataSegment = 0;
  174.     pb -> StartParmSegment = 0;
  175.     pb -> InitRegs.A_Registers [5] = GetgCommon() -> gInitA5;
  176.     pb -> ParentTID = GetTID();
  177.     pb -> stack = 4096;
  178.     pb -> heap = 0;
  179.     pb -> priority = 10;
  180.     pb -> InitRegs.PC = myTask;    // entry point of myTask
  181.  
  182.     if (StartTask (pb) == 0)    // if the task does not get started
  183.         illegal ();                // go debugging
  184. }
  185.